All Objects
Anchor
Image
Link
OBJECT: Link
The
Link
object is a piece of text, an image or an area of an image that loads a hypertext link reference into the target window when selected.
Area
objects are also a type of
Link
object. A link can be created either by using the HTML 'A' or 'AREA' tags, or by calling the
String.link
method. Each 'A' or 'AREA' tag that has an HREF attribute is placed by the JavaScript engine in an array in the
document.links
property. A
Link
object can then be accessed by indexing this array. The following code demonstrates the creation of a link to an anchor in the 'Authors.htm' page using the
String.link
method:
Code:
document.write("AUTHORS".link("Authors.htm#author"))
The exact same link can also be created using HTML as follows:
Code:
<a href="Authors.htm#author">AUTHORS</a>
A
Link
object is a
Location
object and shares the same properties. When you click a
Link
object, the destination document's
referrer
property then contains the URL of the source page. A link can also be used to execute JavaScript code rather than to reference a hyperlink. The following code, for example, simply creates a function to display the message "Hello World!" which is then called if the user clicks on the 'GREETINGS' link:
Code:
<script language="javascript">
function write_hello()
{
document.write("Hello World!")
}
</script>
<a href="javascript:write_hello()">GREETINGS</a>
A full URL takes the following form:
<protocol>//<host>[:<port>]/<pathname>[<hash>][<search>]
PROPERTIES
hash
Property
The
hash
property is a string beginning with a hash (#), that specifies an anchor name in an HTTP URL.
Syntax:
object.
hash
host
Property
The
host
property is a string comprising of the
hostname
and
host
strings.
Syntax:
object.
host
hostname
Property
The
hostname
property specifies the server name, subdomain and domain name (or IP address) of a URL.
Syntax:
object.
hostname
href
Property
The
href
property is a string specifying the entire URL, and of which all other
Link
properties are substrings.
Syntax:
object.
href
pathname
Property
The
pathname
property is a string portion of a URL specifying how a particular resource can be accessed.
Syntax:
object.
pathname
port
Property
The
port
property is a string specifying the communications port that the server uses.
Syntax:
object.
port
protocol
Property
The
protocol
property is the string at the beginning of a URL, up to and including the first colon (:), which specifies the method of access to the URL.
Syntax:
object.
protocol
search
Property
The
search
property is a string beginning with a question mark that specifies any query information in an HTTP URL.
Syntax:
object.
search
target
Property
The
target
property is a string specifying the window that displays the contents of a clicked hyperlink.
Syntax:
object.
target
text Property
The
text
property is a string containing the text of a corresponding 'A' tag.
Syntax:
object.
text
METHODS
handleEvent Method
The
HandleEvent
method invokes the handler for the specified event.
Syntax:
object.
handleEvent
(event)
EVENT HANDLERS
The
Link
object has all of the following event handlers, but the
Area
object can only use the
onDblClick
,
onMouseOut
and
onMouseOver
event handlers.
onClick
EventHandler
The
onClick
event handler executes javaScript code whenever the user clicks (i.e. when the mouse button is pressed and released) on a form object.
Syntax:
onClick
= "myJavaScriptCode"
onDblClick
EventHandler
The
onDblClick
event handler executes JavaScript code whenever the user double clicks on an object in a form.
Syntax:
onDblClick
= "myJavaScriptCode"
onKeyDown
EventHandler
The
onKeyDown
event handler is used to execute certain JavaScript code whenever the user depresses a key.
Syntax:
onKeyDown
= "myJavaScriptCode"
onKeyPress
EventHandler
The onKeyPress event handler executes JavaScript code whenever the user presses or holds down a key
Syntax:
onKeyPress
= "myJavaScriptCode"
onKeyUp
EventHandler
The
onKeyUp
event handler executes JavaScript code whenever the user releases a depressed key.
Syntax:
onKeyUp
= "myJavaScriptCode"
onMouseDown
EventHandler
The
onMouseDown
event handler executes JavaScript code whenever the user depresses the mouse button over an area or link.
Syntax:
onMouseDown
= "myJavaScriptCode"
onMouseOut
EventHandler
The
onMouseOut
event handler executes JavaScript code whenever the mouse pointer leaves an area or a link within that area or link.
Syntax:
onMouseOut
= "myJavaScriptCode"
onMouseUp
EventHandler
The
onMouseUp
event handler executes JavaScript code whenever the user releases a depressed mouse button over an area or link.
Syntax:
onMouseUp
= "myJavaScriptCode"
onMouseOver
EventHandler
The
onMouseOver
event handler cause JavaScript code to be executed whenever the mouse pointer leaves an area or a link within an area or link.
Syntax:
onMouseOver
"myJavaScriptCode"
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information